#ifndef __LOCK__GRARD__HPP__
#define __LOCK__GRARD__HPP__

#include <iostream>
#include <pthread.h>

class LockGuard
{
public:
    LockGuard(pthread_mutex_t* mutex):_mutex(mutex)
    {
        pthread_mutex_lock(_mutex);//构造时加锁
    }

    ~LockGuard()
    {
        pthread_mutex_unlock(_mutex);//析构时解锁
    }
private:
    pthread_mutex_t *_mutex;
};

#endif
